package com.gdones.gpt.bus.notice.controller;


import com.gdones.common.core.annotations.MySysLog;
import com.gdones.common.core.annotations.MySysLogOpration;
import com.gdones.common.core.dto.MyPageBand;
import com.gdones.common.core.dto.MyResult;
import com.gdones.gpt.bus.notice.dto.GptNotice;
import com.gdones.gpt.bus.notice.service.IGptNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author GaoJingBo
 * @since 2023-06-16
 */
@RestController
@RequestMapping("/notice")
@Slf4j
@Api(tags = "通知管理")
public class GptNoticeController {

    @Resource(name = "gptNoticeServiceImpl")
    private IGptNoticeService gptNoticeServiceImpl;

    @GetMapping("/pages")
    @ApiOperation("通知管理-分页")
    @MySysLog(modelName="通知管理",methodDesc = "分页",methodType = MySysLogOpration.GET)
    public MyResult pages(GptNotice dto, MyPageBand pageBand){

        log.debug("--通知管理：分页");
        MyResult result = new MyResult();

        try {
            result = gptNoticeServiceImpl.pages(dto,pageBand);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("通知管理-分页-异常");
        }
        return result;
    }

    @GetMapping("/list")
    @ApiOperation("通知管理-列表不分页")
    @MySysLog(modelName="通知管理",methodDesc = "列表不分页",methodType = MySysLogOpration.GET)
    public MyResult list(GptNotice dto ){

        log.debug("--通知管理：列表不分页");
        MyResult result = new MyResult();

        try {
            result = gptNoticeServiceImpl.mylist(dto);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("通知管理-列表不分页-异常");
        }
        return result;
    }

    @GetMapping("/getByID")
    @ApiOperation("通知管理-查询模型详情")
    @MySysLog(modelName="通知管理",methodDesc = "查询模型详情",methodType = MySysLogOpration.GET)
    public MyResult getByID(String id){

        log.debug("--通知管理：查询模型详情");
        MyResult result = new MyResult();

        try {
            result = gptNoticeServiceImpl.getByID(id);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("通知管理-查询模型详情-异常");
        }
        return result;
    }

    @PostMapping("/add")
    @ApiOperation("通知管理-添加")
    @MySysLog(modelName="通知管理",methodDesc = "添加",methodType = MySysLogOpration.POST)
    public MyResult add(@RequestBody GptNotice dto){

        log.debug("--通知管理：添加");
        MyResult result = new MyResult();

        try {
            result = gptNoticeServiceImpl.add(dto);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("通知管理-添加-异常");
        }
        return result;
    }

    @PutMapping("/update")
    @ApiOperation("通知管理-修改")
    @MySysLog(modelName="通知管理",methodDesc = "修改",methodType = MySysLogOpration.PUT)
    public MyResult update(@RequestBody GptNotice dto){

        log.debug("--通知管理：修改");
        MyResult result = new MyResult();

        try {
            result = gptNoticeServiceImpl.update(dto);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("通知管理-修改-异常");
        }
        return result;
    }

    @DeleteMapping("/deletes")
    @ApiOperation("通知管理-删除")
    @MySysLog(modelName="通知管理",methodDesc = "删除",methodType = MySysLogOpration.DELETE)
    public MyResult deletes(String ids){

        log.debug("--通知管理：删除");
        MyResult result = new MyResult();

        try {
            result = gptNoticeServiceImpl.deletes(ids);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("通知管理-删除-异常");
        }
        return result;
    }


    @PostMapping("/sendEmail")
    @ApiOperation("通知管理-群发邮件")
    @MySysLog(modelName="通知管理",methodDesc = "群发邮件",methodType = MySysLogOpration.POST)
    public MyResult sendEmail(String id){

        log.debug("--通知管理：群发邮件");
        MyResult result = new MyResult();

        try {
            result = gptNoticeServiceImpl.sendEmail(id);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("通知管理-群发邮件-异常");
        }
        return result;
    }

    @PutMapping("/updateToTc")
    @ApiOperation("通知管理-设置为开屏弹窗")
    @MySysLog(modelName="通知管理",methodDesc = "设置为开屏弹窗",methodType = MySysLogOpration.PUT)
    public MyResult updateToTc(String id){

        log.debug("--通知管理：设置为开屏弹窗");
        MyResult result = new MyResult();

        try {
            result = gptNoticeServiceImpl.updateToTc(id);
        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("通知管理-设置为开屏弹窗-异常");
        }
        return result;
    }

}
